<?php
//Zend_Loader::loadFile('../application/admin/models/Template.php');
class Hotel 
{
    /**
     * @var object Zend DB Adapter
     */
    private $_db;
    /**
     * @var string
     */
   
    public function __construct()
    {
			$this->_db = Zend_Registry::get('db');
    }
    
    public function listHotels()
    {
    	$getNewsletters = $this->_db->fetchAll("
			select* from hotels
			
		");
		
		return $getNewsletters;
	}
	

    public function getHotel($hotel_id)
    {
    	//echo $hotel_id;exit;
    $sql="
			select hotel_id,hotel_title,hotel_city,hotel_country,hotel_description,
    	 hotel_contactperson,hotel_phone,hotel_fax,hotel_skype,is_Enabled
			from  hotels where   hotel_id='".$hotel_id."'
			
		";
  // echo $sql;exit;
    	$getHotel = $this->_db->fetchrow($sql);
	//	print_r($getHotel);exit;
		return $getHotel;
       
    }

    public function addHotel($hotel_title, $hotel_city,$hotel_country,$hotel_description,$hotel_contactperson,$hotel_phone,$hotel_fax,$hotel_skype,$is_Enabled)
    {
    	 $sql="insert into hotels 
    	 (hotel_title,hotel_city,hotel_country,hotel_description,
    	 hotel_contactperson,hotel_phone,hotel_fax,hotel_skype,is_Enabled) values
    	 ('".$hotel_title."','".$hotel_city."','".$hotel_country."','".$hotel_description."',
    	 '".$hotel_contactperson."','".$hotel_phone."','".$hotel_fax."','".$hotel_skype."',$is_Enabled)";
    	$addhotel=$this->_db->exec($sql);
        return  $addhotel;
    } 

    public function updatehotel($hotel_id,$hotel_title, $hotel_city,$hotel_country,$hotel_description,$hotel_contactperson,$hotel_phone,$hotel_fax,$hotel_skype,$is_Enabled)
    {
     $sql=" update  Hotels set hotel_title='".$hotel_title."' ,hotel_city='".$hotel_city."',hotel_country='".$hotel_country."' ,
      hotel_description='".$hotel_description."',hotel_contactperson='".$hotel_contactperson."',hotel_phone='".$hotel_phone."',
      hotel_fax='".$hotel_fax."',hotel_skype='".$hotel_skype."',is_Enabled='".$is_Enabled."' where  hotel_id=".$hotel_id."
		";
    	/*$command="call proc_hotel('EDIT','".$hotel_title."','".$hotel_content."',".$template_id.",".$hotel_id.",1)";
    	//echo  $command;exit;
		$EditHotels = $this->_db->exec($command);*/
       $EditHotels = $this->_db->exec($sql);
		return $EditHotels;
        
    }

    public function deletehotel($hotel_id)
    {
    	$command="delete from Hotels where hotel_id=".$hotel_id."";
    	
    	//echo $command;exit;
       $DeleteHotels = $this->_db->exec($command);
      
		return $DeleteHotels;
        
    }
    
    public function listCountriesforhotel()
    {
    	$options = $this->_db->fetchPairs("
			select  countryid,country_name
			from countries 
			
		");
		
		return $options;
	}
	
 public function getCity($country)
    {
    	$sql="select  cityid,city_name from cities where  countryid=".$country."";
    	//echo $sql;exit;
    	$options = $this->_db->fetchAll($sql);
    	
    	
		
		return $options;
	}
public function assignroomcats($roomcats,$hotel_id)
  {
  	
  	   $this->_db->exec("SET AUTOCOMMIT=0");
  	   $this->_db->exec("START TRANSACTION");
  	   $sql="delete from  hotelrooms  where hotel_id=".$hotel_id."";
		$deleteroomcatshotel = $this->_db->exec($sql);
		
			foreach ($roomcats as $value) {
				$sql1="insert into hotelrooms (hotel_id,roomcat_id) values(".$hotel_id.",".$value['roomcat_id'].")";
				//echo $sql1;exit;
				$addroomcats=$this->_db->exec($sql1);
			}
			
			if($deleteroomcatshotel &&  $addroomcats) { 
			
			   $this->_db->exec("COMMIT");
			}
			else { 
			
			    $this->_db->exec("ROLLBACK");
			
			}
		return $addroomcats;
  	
  }
    

}

